package com.imau.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 模拟用户登录请求
 * 用户名 user
 * 密码 pass
 */
@WebServlet("/webDemo")
public class ServletWebDemo extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1.获取请求参数  ?user=admin&pass=123456
        String user = req.getParameter("user");
        String pass = req.getParameter("pass");

        System.out.println(user+"======"+pass);

        //2.封装响应

        resp.setHeader("Content-Type","text/html;charset=UTF-8");
        //2.2 写数据 输出流 Java IO

        PrintWriter out = resp.getWriter();

        //可以写网页代码
        out.write("<html> <head> <title>teset</title></head><body><h3>欢迎登录</h3><body></html>");


    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
}
